<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // var arr = [6,7,8,9,10,15,20]

    // arr.reduce(function(a,b,c){
    //     console.log(a + b);
    //     return a+b
    // },0)

    var obj = {
        data: {
            data: {
                name: 'sss'
            }
        }
    }

    var str = 'data.data.name'
    //要求  通过字符串str拿到真实的值 使用reduce
    var arr = str.split('.')
    // console.log(arr);
    var name = arr.reduce(function (a, b, c) {
        return a[b]
    }, obj)
    console.log(name);
</script>

</html>